package net.wanho.controller;

import cn.hutool.json.JSONUtil;
import net.wanho.server.WebSocketServer;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * Author：汤小洋
 * Date：2024-01-17 17:25
 * Description：<描述>
 */
@RestController
@RequestMapping("/orders")
public class OrderController {

    @Resource
    private WebSocketServer webSocketServer;

    @GetMapping("/reminder/{orderId}")
    public AjaxResult reminder(@PathVariable Integer orderId){
        // 基于WebSocket发送消息，实现催单
        Map<String,Object> map = new HashMap<>();
        map.put("type", 1); // type指定消息类型，1表示催单  2新订单
        map.put("orderId", orderId); // 订单id
        map.put("orderNumber", "166390340433"); // 订单号
        webSocketServer.sendToAllClient(JSONUtil.toJsonStr(map));


        return  AjaxResult.success();
    }


}
